package com.tianyi.dao;

import com.tianyi.application.dto.MyUserDto;
import com.tianyi.domain.entity.MyUserEntity;
import com.tianyi.domain.repository.IMyUserRepository;
import com.tianyi.domain.services.MyUserSerice;
import com.tianyi.mapper.MyUserMapper;
import com.tianyi.po.MyUserPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MyUserRespository implements IMyUserRepository {

    @Autowired
    IMyUserDao myUserDao;

    /**
     * @param myUser
     * @return
     */
    public MyUserEntity save(MyUserEntity myUser) {
        MyUserPO myUserPO = MyUserMapper.INSTANCE.myuser2PO(myUser);
        return MyUserMapper.INSTANCE.myUserPO2Entity(myUserDao.save(myUserPO));
    }


    /**
     * 根据用户名称去找数据，有可能出现的是多个数据，所以返回值使用lsit
     * @param userName 用户名
     * @return 用户列表
     */
    public List<MyUserEntity> find(String userName) {
        return MyUserMapper.INSTANCE.myUserPOs2Entity(myUserDao.findByUserName(userName));
    }
}
